<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo Yii::$app->name;?> 后台管理</title>
<?php $this->HeaderView(['slide']);?>

<script type="text/javascript" src="<?php echo $this->root_dir; ?>/static/common/js/jquery.tablednd.js"></script>
</head>
<body class="view_form" id="view_form_Model">

        <form class="view-form-form" method="post" action="<?php echo $this->createUrl([$model->modelid ? 'mobo/models/update' : 'mobo/models/create', 'modelid'=>$model->modelid]);?>" enctype="multipart/form-data">
        <input type="hidden" id="catid" name="Models[modelid]" value="<?php echo $model->modelid;?>">
        <input type="hidden" id="type" name="Models[type]" value="<?php echo $model->type;?>">
                    <div class="slideTxtBox mtop-0">
        <div class="hd">
                    <ul>
                
                <li><a href="javascript:;"><span></span>基础信息</a></li>
                <li><a href="javascript:;"><span></span>后台首页</a></li>
            </ul>
                </div>
        <div class="bd">
                    <ul>
            <table class="view-form-input" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">模型名称：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="name" name="Models[name]" value="<?php echo $model->name;?>"></td>
                    </tr>

                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">数据库表名：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="tablename" name="Models[tablename]" value="<?php echo $model->tablename;?>" <?php echo $model->modelid ? ' readonly="readonly"' : ''?>> 不含表前缀</td>
                    </tr>

                    
                                        <tr>
                        <th valign="top" class="td-title"><label for="catid">设置：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="setting" name="Models[setting]" value=""></td>
                    </tr>
                        </tbody>
            </table>
            </ul>
            <?php if($model->modelid){?>
             <ul>
            <table class="view-form-input" id="setting-index" border="0" cellspacing="0" cellpadding="0" width="100%">
                <tbody>
                    <tr>
                        <th valign="top" class="td-title"><label for="catid">管理首页视图：</label></th>
                        <td class="td-input"><input type="text" class="input-text" id="index_template" name="Models[index][views]" value="<?php echo @$model->setting['index']['views']?>"> 默认为：modelsform_index</td>
                    </tr>
<tr>
                        <th valign="top" class="td-title"><label for="catid">仅显示一级分类：</label></th>
                        <td class="td-input">
                        <?php
						

echo common\widgets\CommonWidget::widget(['viewPath'=>'switchbutton', 'options' => [
	'id'=> 'setting-index-onlytop',
	'name'=> 'Models[setting][index][onlytop]',
	'value'=> @$model->setting['index']['onlytop'],
	'attributes'=> array_merge($model->attributes, array('id'=>$model->modelid)),
	'model'=> $model,
	'setting'=> ['defaultvalue'=>1]

]]);
?>
                        
                        </td>
                    </tr>
                <?php
				//print_r($models['fields']);
				//exit;
				$listorder = isset($model->setting['index']['listorder']) ? $model->setting['index']['listorder'] : $models['fields'];
				//$fields = isset($model->setting['index']['listorder']) ? $model->setting['index']['listorder'] : array();
				
				//print_r($fields);
				//print_r($models['fields']);
				//exit;
				foreach($fields  as $k=>$val){
					$v = is_array($val) ? $val : (isset($models['fields'][$val]) ? $models['fields'][$val] : $models['fields'][$k]);
				?>
                                        <tr>
                                        <input type="hidden" class="input-text" name="Models[setting][index][listorder][]" value="<?php echo $v['fieldid']?>">
                        <th valign="top" class="td-title"><label for="catid"><?php echo $v['name']?>： <span class="btn-checkbox"><input type="checkbox" value="<?php echo $v['field']?>" name="Models[setting][index][fields][]" <?php echo @@in_array($v['field'], $model->setting['index']['fields']) ? ' checked' : '';?> /></span></label></th>
                        <td class="td-input"><input type="text" class="input-text" name="Models[setting][index][values][<?php echo $v['fieldid']?>]" value="<?php echo @$model->setting['index']['values'][$v['fieldid']];?>"> TH:<input type="text" class="input-text" name="Models[setting][index][th][<?php echo $v['fieldid']?>]" value="<?php echo @$model->setting['index']['th'][$v['fieldid']];?>"></td>
                    </tr>
               <?php
				}
				?>
  
                        </tbody>
            </table>
            </ul>
            <?php
			}
			?>
                </div>
    </div>
    <input type="submit" value="提交" name="sbmt" class="btn-submit mt-10" style="margin-left:120px">
<?=$this->csrfToken()?>

    </form>
<script type="text/javascript">
jQuery(".slideTxtBox").slide({trigger:"click"});
$(function(){
	$(".view-form-form").validate({	
		rules: {
			"Models[name]": {
				required: true,
			},
			"Models[tablename]": {
				required: true,
				remote: {
					url: "<?php echo $this->createUrl(['/mobo/models/check-tablename'])?>",     //后台处理程序
					type: "get",               //数据发送方式
					dataType: "json",           //接受数据格式   
					data: {  
					    modelid: '<?php echo $model->modelid?>',                   //要传递的数据
						tablename: function() {
							return $("#tablename").val();
						}
					}
			}
			}
		},
		messages: {
			"Models[name]": {
				required: '请输入模型名称',
			}
		}
	});
    $("#setting-index").tableDnD();	
	
});
</script> 
<?php $this->FooterView();?>
</body>
</html>
